<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title></title>
</head>
<body>
<style>
    #div {
        width: 200px;
        height: 200px;
        padding: 20px;
        background: red;
        border: 10px solid #000;
        box-sizing: border-box;
        /*background-clip: content-box;*/
    }
</style>
<div id="div">

</div>
<style>
    .c-0 {
        display: flex;
        width: 100%;
        height: 200px;
    }

    .c-1 {
        width: 100px;
        height: 100px;
        background: red;
        flex: 1;
    }

    .c-2 {
        flex: 1;
        background: blue;
    }
</style>
<ul class="c-0">
    <li class="c-1"></li>
    <li class="c-2"></li>
    <li class="c-1"></li>
</ul>
<script type="text/javascript" src="js/stack.js"></script>
<script type="text/javascript" src="js/binarySearchTree.js"></script>
<script type="text/javascript" src="js/subscribe_publish.js"></script>
<script>
    var testBST = new BST();
    testBST.insert(23);
    testBST.insert(45);
    testBST.insert(16);
    testBST.insert(37);
    testBST.insert(3);
    testBST.insert(99);
    testBST.insert(22);
    //testBST.inOrder(testBST.root);
    //testBST.preOrder(testBST.root);
    //testBST.postOrder(testBST.root);
    //testBST.nonRecursiveInOrder();
    // var test = new Stack();
    // test.push(1);
    // test.pop();
    // console.log(test.peek());


    var observer = new Observer();

    var testObserver = new test('test');

    observer.on('test', testObserver.test);
    observer.emit('test')
</script>
<script type="text/javascript" src="js/graph.js"></script>
<script>
    g = new Graph(5);
    g.addEdge(0, 1);
    g.addEdge(0, 2);
    g.addEdge(1, 3);
    g.addEdge(2, 4);
    g.dfs(0);
    g.bfs(0);
    //var vertex = 4;
    //var paths = g.pathTo(vertex);
    // while (paths.length > 0) {
    //     if (paths.length > 1) {
    //         console.log(paths.pop() + '-');
    //     }
    //     else {
    //         console.log(paths.pop());
    //     }
    // }
</script>
<script>
    function Person() {

    }

    var p = new Person();
    Person.prototype = {
        a: 1
    }
    var p2 = new Person();
    console.log(p.a);
    console.log(p2.a);
</script>
<script>
    function createFunctions() {
        var result = new Array();
        for (var i = 0; i < 10; i++) {
            result[i] = function () {
                return i;
            };
        }
        console.log(result[0]());
        return result;
    }

    console.log(createFunctions());
</script>
<script>
    function People() {

        this.name = 'Tom';

        this.age = 24;

        this.c = function () {

            console.log('1');
        }
    }

    People.prototype.look = function () {
        console.log('look at this');
    }
    var b = new People();
    //使用Object.defineProperty方法为b添加一个'sex'的不可枚举属性
    Object.defineProperty(b, 'sex', {
        value: '女',
        enumerable: false
    });
    for (var i in b) {
        console.log(i);
    }
    console.log(Object.keys(b));
</script>
<script>
    var name = 'globalName';

    function funcA() {
        //当funcA()被调用时，刚进入funcA的执行环境，其作用域链最前端的funA activation object里有name属性，值为undefined。
        console.log(name);//undefined
        var name = 'funAName';
        console.log(name);//'funAName'
        //console.log(age);//报错
    }

    funcA();

    var color = "blue";

    function changeColor() {
        console.log(color + '-----');
        if (color === "blue") {
            color = "red";
        } else {
            color = "blue";
        }
    }

    changeColor();
    //alert("Color is now " + color); red
</script>
<script>
    console.log(1 === new Number(1))

    function num() {
        return 1;
    }

    console.log(1 == num);
</script>
<script>
    //柯里化
    function add(x) {
        return function (y) {
            return x + y;
        }
    }

    console.log(add(1)(2), '0000000')

    function zzzz() {
        console.log(this)
    }
</script>
<div onclick="zzzz()">zzzzz</div>
<script>
    //借用构造函数继承
    var superfn = function () {
        this.a = 1
    };
    superfn.prototype = {
        b: function () {
            return ++this.a;
        }
    }
    var subfn = function () {
        superfn.call(this);
    }
    var supObj = {
        a: ['1'],
        b: function () {
            return this.a[0];
        }
    };

    function obj(o) {
        function F() {
        }

        F.prototype = o;
        return new F();
    }

    var instace = obj(supObj).b();

    console.log('list');
    // var timer = null;
    // timer = setInterval(function () {
    //     console.log(8);
    //     clearInterval(timer)
    // },1000);

    // (function () {
    //     console.log(0);
    // }());
    // setTimeout(function () {
    //     console.log(1);
    // }, 0);
    // new Promise(function (resolve, reject) {
    //     console.log(2);
    //     resolve(3);
    // }).then(function (val) {
    //     console.log(val);
    //     new Promise(function (resolve, reject) {
    //         console.log(4);
    //         resolve(5);
    //     }).then(function (val) {
    //         console.log(val);
    //     });
    // });
    // console.log(6);


    a = 'zz';
    var a;
    console.log(a);


    var z = 3;

    function fn1() {
        var z = 1;
        console.log(this.z + z, '+++');
    }

    function fn2() {
        var z = 2;
        fn1();
    }

    function Fn3() {
        this.z = 4;
    }

    Fn3.prototype = {
        z: 5,
        al: function () {
            console.log(this.z, z, '00000')
        }
    };

    fn2();

    var fn4 = new Fn3();
    fn4.al();
    fn4.al.call(fn1);


    console.log('begin');
    for (var x = 0; x < 5; x++) {
        setTimeout(function () {
            console.log(x);
        }, 1000)
    }
    console.log('end');

    function pro() {
        var index = 0;
        return {
            add: function () {
                index++;
                console.log(index)
            },
            index: function () {
                return index;
            }
        }
    }

    var p = pro();
    p.add();
    console.log(p.index(), '=======');

    var testPromise = new Promise((resolve, reject) => {
        resolve('resolve');
    });
    testPromise.finally(() => {
        console.log('finally');
    }).then((data) => {
        console.log(data)
    });

    var project = {
        count: 0,
        add: function () {
            this.count++
        }
    };

    var subProject = Object.create(project, {
        // count: {
        //     value: 0
        // }
    });

    project.add();
    console.log('project', project);
    console.log('subProject', subProject);

    async function f() {
        await new Promise(resolve => {
            console.log('async-1');
            resolve()
        });
        console.log('async-2')
    }

    f();

    async function f2() {
        var a = await 1;
        var b = await a + 1;
        console.log('async-3', b)
    }

    f2();

    var f3 = function () {
        return setTimeout(function () {
            return 'async-return'
        }, 0);
    };

    console.log(f3);

</script>
</body>
</html>
